package com.beyondsoft.common.core.sys.exception;

import com.beyondsoft.common.core.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理Controller抛出的异常.
     *
     * @param e 抛出异常.
     * @return 响应类.
     */
    @ExceptionHandler(value = Exception.class)
    public R exception(Exception e) {
        if (e instanceof GeneralException) {
            log.info("业务异常");
        }
        log.error("全局异常信息 e={}", e.getMessage(), e);
        return new R<>(e);
    }

}